#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#define endl "\n"
using namespace std;
int n, k = 0;
char a[10][10], z;
int fangxiang[4][2] = { {1,0},{-1,0},{0,-1},{0,1} };
bool pan[10][10];
bool panduan(int x, int y)
{
	if (x < 0 || x >= n || y < 0 || y >= n)
		return 0;
	if (pan[x][y] == 1 || a[x][y] == '0' || a[x][y] != z)
		return 0;
	return 1;
}
void bfs(int x, int y)
{
	for (int i = 0; i < 4; i++)
	{
		int ax = x + fangxiang[i][0];
		int ay = y + fangxiang[i][1];
		if (panduan(ax, ay))
		{
			k++;
			pan[ax][ay] = 1;
			bfs(ax, ay);
			return;

		}
	}

}
int main()
{
	int mun = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (pan[i][j] != 1 && a[i][j] != '0')
			{
				k = 1, z = a[i][j];
				pan[i][j] = 1;
				bfs(i, j);
				mun = mun + k % 2;
			}
		}
	}
	cout << mun << endl;
	return 0;
}
